wavefront(ρ, θ, OPD, n_max)
Estimates wavefront error by expressing optical aberrations as a linear combination of weighted Zernike polynomials using a linear least squares method. The accuracy of this type of wavefront reconstruction represented as an expanded series depends upon a sufficiently sampled phase field and a suitable choice of the fitting order n_max.
ρ, θ, and OPD must be floating-point vectors of equal length; at each specific index the values are elements of an ordered triple over the exit pupil.
ρ: normalized radial exit pupil position variable{0 ≤ ρ ≤ 1};θ: angular exit pupil variable in radians(mod 2π), defined positive counter-clockwise from the horizontal x-axis;OPD: measured optical path difference in waves;n_max: maximum radial degree to fit to.
Note that specifying n_max will fit using the full range of Zernike polynomials from j = 0 to j_max corresponding to the last polynomial with degree n_max. If instead you only want to fit to a subset of Zernike polynomials you can specify a vector of (m, n) tuples in place of n_max using the method:
wavefront(ρ, θ, OPD, orders::Vector{Tuple{Int, Int}})If your phase data is in the form of a floating-point matrix instead you can call the method:
wavefront(OPD, fit_to; options...)This assumes the wavefront error was uniformly measured using polar coordinates; the matrix is expected to be a polar grid of regularly spaced periodic samples with the first element referring to the value at the origin and the end points including the boundary of the pupil (i.e. ρ, θ = 0.0:step:1.0, 0.0:step:2π). The first axis of the matrix (the rows) must correspond to the angular variable θ while the second axis (the columns) must correspond to the radial variable ρ.
If instead your data is not equally spaced you can call:
wavefront(ρ::Vector, θ::Vector, OPD::Matrix, fit_to; options...)under the aforementioned dimensional ordering assumption.
fit_to can be either n_max::Int or orders::Vector{Tuple{Int, Int}}.
It is also possible to input normalized Cartesian coordinates using the method with 3 positional arguments and passing fit_to as a keyword argument:<br> wavefront(x, y, OPD; fit_to, options...);<br> This accepts vectors and matrices for the phase; in this case, if OPD is a matrix the shape of the axes is assumed to be x-by-y.
The function returns six values contained within a WavefrontOutput type, with fields:
recap: vector of named tuples containing the Zernike polynomial indices and the corresponding expansion coefficients rounded according toprecision;v: full vector of Zernike wavefront error expansion coefficients;ssr: the sum of the squared residuals from the fit;metrics: named 3-tuple with the peak-to-valley error, RMS wavefront error, and Strehl ratio;W: theWavefrontfunctionΔW(ρ, θ);fig: theMakieFigureAxisPlot.